package controllers

import (
	"huxiaopang/models"
	"time"
)

type UploadLogController struct {
	ApiBaseController
}

// @router /logurl [post]
func (this *UploadLogController) LogUrl() {
	bean := BaseBean{}
	storeCode := this.GetString("store_code", "")

	uploadLogUrl := this.GetString("upload_log_url")
	if len(uploadLogUrl) == 0 {
		bean.Code = "-1"
		bean.Message = "upload_log_url不能为空"
		this.Data["json"] = bean
		this.ServeJSON()
		return
	}

	devId := this.GetString("dev_id")
	if len(devId) == 0 {
		bean.Code = "-1"
		bean.Message = "dev_id不能为空"
		this.Data["json"] = bean
		this.ServeJSON()
		return
	}

	//先插入订单，然后调用H5接口
	uploadLogData := models.UploadLogData{}
	uploadLogData.DeviceId = devId
	uploadLogData.StoreCode = storeCode
	uploadLogData.UploadLogUrl = uploadLogUrl
	uploadLogData.CreateTime = time.Now().Format("20060102150405")
	if err := uploadLogData.Insert(); err != nil{
		bean.Code = "-1"
		bean.Message = err.Error()
		this.Data["json"] = bean
		this.ServeJSON()
		return
	}
	this.Data["json"] = map[string]interface{}{
		"code": "0",
		"msg":  "SUCCESS",
		"data": "",
	}
	this.ServeJSON()
	return

}
